using System;
using System.Collections.Generic;
using System.Linq;

namespace DebuggableInstallableService
{
    public static class TypeExtensions
    {
        public static IEnumerable<T> GetAttributes<T>(this Type typeWithAttributes) where T: Attribute
        {
            object[] configAttribs = Attribute.GetCustomAttributes(typeWithAttributes, typeof (T), false);

            if(configAttribs != null && configAttribs.Length > 0)
            {
                foreach (T configAttrib in configAttribs)
                {
                    yield return configAttrib;
                }
            }
        }

        public static T GetAttribute<T>(this Type typeWithAttributes) where T: Attribute
        {
            return GetAttributes<T>(typeWithAttributes).FirstOrDefault();
        }
    }
}